package com.krlin.soccer.soccer.service;

import com.krlin.soccer.soccer.entity.Queue;
import com.krlin.soccer.soccer.mapper.CoachMapper;
import com.krlin.soccer.soccer.mapper.QueueMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QueueService {

    @Autowired
    QueueMapper queueMapper;

    @Autowired
    CoachMapper coachMapper;

//    @Cacheable(value = {"quques"}, key = "")
    public List<Queue> getQueues() {
        List<Queue> queues = queueMapper.getQueues();

        queues.forEach( e -> {
            String id = e.getCoachId();
            String name = coachMapper.selectByPrimaryKey(id).getCoachName();
            e.setCoachId(name+"【"+id+"】");
        });

        return queues;
    }

    public Queue getQueueById(Integer id) {
        return queueMapper.selectByPrimaryKey(id);
    }

    public int updateQueue(Queue queue) {
        return queueMapper.updateByPrimaryKeySelective(queue);
    }

    public int insertQueue(Queue queue) {
        return queueMapper.insertSelective(queue);
    }

    public int deleteQueue(Integer id) {
        return queueMapper.deleteByPrimaryKey(id);
    }
}
